﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace gamecontrol
{
    public class InputMouse : InputBase
    {
        private double mouseHorizontalPosition;

        public InputMouse(FrameworkElement elem):
            base(elem)
        {}

        public override void handleOnLoaded(object sender, EventArgs e)
        {
            iElement.Margin = new Thickness(extend / 2, 0, 0, 0);
            Application.Current.RootVisual.MouseMove += RootVisual_MouseMove;
            Application.Current.RootVisual.MouseEnter += RootVisual_MouseEnter;
        }

        void RootVisual_MouseEnter(object sender, MouseEventArgs e)
        {
            iElement.SetValue(Canvas.LeftProperty, e.GetPosition(null).X);
        }

        void RootVisual_MouseMove(object sender, MouseEventArgs e)
        {
            double x = e.GetPosition(null).X;
            
            double deltaH = x - mouseHorizontalPosition;
            double newLeft = deltaH + (double)iElement.GetValue(Canvas.LeftProperty);
            iElement.SetValue(Canvas.LeftProperty, newLeft);
            mouseHorizontalPosition = x;
        }

        public override void handle()
        {}
    }
}